/**
 * Created with IntelliJ IDEA.
 * Description:
 * https://gitee.com/li--jiaqiang/java-test.git
 * git pull
 * git pull origin master
 * git pull origin master --allow-unrelated-histories
 * User: 86187
 * Date: 2022-05-07
 * Time: 20:53
 */

//Scanner scan = new Scanner(System.in);

import java.util.Scanner;

public class TsetDemo2 {

    /**
     * 二分查找，找到返回true,否则返回false
     * @param array
     * @return
     */
    public static boolean myBinarySearch(int[] array,int key) {
        int left = 0;
        int right = array.length - 1;

        while(left <= right) {
            int mid = (left + right) / 2;
            if(array[mid] == key) {
                return true;
            } else if(array[mid] < key) {
                left = mid + 1;
            } else {
                right = mid - 1;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        int[] array = {1,5,8,12,25,30};

        System.out.println(myBinarySearch(array, 13));
    }

}
